<template>
  <div v-if="show" class="promotion-dialog">
    <div class="dialog-content">
      <h3>选择升变棋子</h3>
      <div class="piece-options">
        <div
          v-for="piece in pieces"
          :key="piece"
          class="piece-option"
          @click="selectPiece(piece)"
        >
          <ChessPiece :piece="`${color}-${piece}`" />
        </div>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
import { defineProps, defineEmits } from 'vue'
import ChessPiece from './ChessPiece.vue'

const props = defineProps<{
  show: boolean
  color: 'white' | 'black'
}>()

const emit = defineEmits<{
  (e: 'select', piece: string): void
}>()

const pieces = ['queen', 'rook', 'bishop', 'knight']

const selectPiece = (piece: string) => {
  emit('select', piece)
}
</script>

<style scoped>
.promotion-dialog {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 1000;
}

.dialog-content {
  background: white;
  padding: 20px;
  border-radius: 8px;
  text-align: center;
}

.piece-options {
  display: flex;
  gap: 10px;
  margin-top: 20px;
}

.piece-option {
  width: 60px;
  height: 60px;
  cursor: pointer;
  border: 2px solid transparent;
  border-radius: 4px;
  padding: 5px;
}

.piece-option:hover {
  border-color: #4CAF50;
  background: rgba(76, 175, 80, 0.1);
}
</style> 